<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px" @submit.native.prevent>
      <el-form-item label="店铺名称" prop="shopName">
        <el-input
          v-model="queryParams.shopName"
          placeholder="请输入店铺名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      todo 缺少字段-->
<!--      <el-form-item label="资金流动类型" prop="">
        &lt;!&ndash;        <dict-select :options="dict.type.user_type" v-model="queryParams.enable" placeholder="请选择用户类型"/>&ndash;&gt;
      </el-form-item>
      <el-form-item label="收支类型" prop="">
        &lt;!&ndash;        <dict-select :options="dict.type.user_type" v-model="queryParams.enable" placeholder="请选择用户类型"/>&ndash;&gt;
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="balanceList">
<!--      <el-table-column label="用户名" align="center" prop="userName" :show-overflow-tooltip="true" width="160"/>-->
      <el-table-column label="店铺名" align="center" prop="shopName" :show-overflow-tooltip="true" width="220"/>
<!--      <el-table-column label="类型" align="center" prop="type" :show-overflow-tooltip="true" width="160">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.water_type" :value="scope.row.type"></dict-tag>
        </template>
      </el-table-column>-->
<!--      <el-table-column label="数量" align="center" prop="" :show-overflow-tooltip="true" width="160"/>-->
      <el-table-column label="总余额" align="center" prop="totalBalance" :show-overflow-tooltip="true" width="180">
        <template slot-scope="scope">
          <span>{{ formatter(scope.row, 'totalBalance') }}</span>
        </template></el-table-column>
      <el-table-column label="当前可用余额" align="center" prop="availableBalance" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ formatter(scope.row, 'availableBalance') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="类型" align="center" prop="type" :show-overflow-tooltip="true" width="160">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.water_type" :value="scope.row.type"></dict-tag>
        </template>
      </el-table-column>-->
<!--      <el-table-column label="发生时间" align="center" prop="payDate" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payDate, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="冻结收入" align="center" prop="freezeIn" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ formatter(scope.row, 'freezeIn') }}</span>
        </template></el-table-column>
      <el-table-column label="冻结支出" align="center" prop="freezeOut" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ formatter(scope.row, 'freezeOut') }}</span>
        </template></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
           <el-button size="mini" type="text" icon="el-icon-edit" @click="showBalanceSlip(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 金额交易记录 -->
    <el-dialog title="交易记录" :visible.sync="openDetails" width="1400px" append-to-body
               :close-on-click-modal="false" @close="queryParamsDel.pageNum = 1">
      <el-card class="box-card">
        <!-- <div slot="header" class="clearfix">
          <span>店铺余额列表</span>
        </div> -->
        <div>
          <el-form :model="queryParamsDel" ref="queryParamsDel" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="资金变动类型" prop="category">
              <dict-select :options="dict.type.bus_type" v-model="queryParamsDel.category" placeholder="请选择资金变动类型"></dict-select>
            </el-form-item>
            <el-form-item label="交易类型" prop="code">
              <dict-select :options="dict.type.bus_type_detail" v-model="queryParamsDel.code" placeholder="请选择交易类型"></dict-select>
            </el-form-item>
            <el-form-item label="收支" prop="inOut">
              <dict-select :options="dict.type.balance_inOut" v-model="queryParamsDel.inOut" placeholder="请选择收支"></dict-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="searchDetails">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetSearchDetails">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div>
          <el-table v-loading="loadingDetail" :data="detailsList" style="width:auto !important;">
            <el-table-column label="店铺名" align="center" prop="shopName" />
            <el-table-column label="发生金额" align="center" prop="amountIncurred">
              <template slot-scope="scope">
                <span>{{ formatter(scope.row, 'amountIncurred') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="交易类型" align="center" prop="type" width="100" >
              <template slot-scope="scope">
                <dict-tag :options="dict.type.water_type" :value="scope.row.type"></dict-tag>
              </template>
            </el-table-column>
            <el-table-column label="变动" align="center" prop="inOut" width="100">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.balance_inOut" :value="scope.row.inOut" />
              </template>
            </el-table-column>
            <el-table-column label="业务单号" align="center" prop="businessNo" width="200" />
            <el-table-column label="交易后余额" align="center" prop="payAfter">
              <template slot-scope="scope">
                <!--                <span>{{ formatter(scope.row, 'payAfter') }}</span>-->
                {{$yun.priceFormatter( JSON.parse(scope.row.payAfter).availableBalance)}}
              </template></el-table-column>
<!--            <el-table-column label="交易后余额" align="center" prop="payBefore">
              <template slot-scope="scope">
                <span>{{ formatter(scope.row, 'payBefore') }}</span>
              </template></el-table-column>-->
            <el-table-column label="交易时间" align="center" prop="payDate" width="120">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.payDate, '{m}/{d}/{y}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="交易备注" align="center" prop="description" />
             <el-table-column label="类别" align="center" prop="category" >
            
             </el-table-column>
            <el-table-column label="交易类型" align="center" prop="code" width="150">
         
            </el-table-column>
          </el-table>

          <pagination v-show="balanceSlipTotal > 0" :total="balanceSlipTotal"
                      :page.sync="queryParamsDel.pageNum" :limit.sync="queryParamsDel.pageSize"
                      @pagination="getBalanceSlip" />
        </div>
      </el-card>

    </el-dialog>
  </div>
</template>

<script>
import {balanceList,getBalanceSlip} from "@/api/store/storeFuns";
import Template from '@/views/setting/template/index.vue'
export default {
  name: "Balance",
  components: { Template },
  dicts:['water_type','transaction_type','bus_type','balance_inOut','bus_type_detail'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 店铺余额表格数据
      balanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        shopId:null,
      },
      openDetails:false,
      loadingDetail:false,
      detailsList:[],
      queryParamsDel:{
        pageNum:1,
        pageSize:10
      },
      balanceSlipTotal:0,
      shopId:null,
    };
  },
  created() {
    if(this.$route.query.shopId){
      this.queryParams.shopId = this.$route.query.shopId;
    }
    this.getList();
  },
  methods: {
    /** 查询店铺余额列表 */
    getList() {
      this.loading = true;
      balanceList(this.queryParams).then(response => {
        this.balanceList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pageSize:10,
        pageNum:1
      };
      this.resetForm("form");
    },
    /** 搜索资金列表*/
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      // this.handleQuery();
      this.queryParams={
        pageNum: 1,
          pageSize: 10,
      };
      this.getList()
    },
    //格式化金额
    formatter: function (row, key) {
      return this.$yun.priceFormatter(row[key]);
    },
    //查看交易记录
    showBalanceSlip: function (row) {
      this.openDetails = true;
      this.shopId = row.shopId;
      this.getBalanceSlip();
    },
    //获取交易记录
    getBalanceSlip: function () {
      this.loadingDetail = true;
      this.queryParamsDel.shopId = this.shopId;
      getBalanceSlip(this.queryParamsDel).then(response => {
        this.detailsList = response.data.records;
        this.balanceSlipTotal = response.data.total;
        this.loadingDetail = false;
      });
    },
    //搜索交易记录
    searchDetails: function () {
      this.queryParamsDel.pageNum = 1;
      this.getBalanceSlip();
    },
    //重置交易记录
    resetSearchDetails: function () {
      this.resetForm("queryParamsDel");
      this.searchDetails();
    },
  }
};
</script>
